package com.sharekitchen.mapper;

import com.sharekitchen.dto.RoomDto;
import com.sharekitchen.entity.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RoomMapper {

//    查询全部

    @Select("SELECT * FROM `room` WHERE is_delete=0")
    List<Room> findAllRoom();

    //    查询房间设备表
    @Select("SELECT * FROM `room_device` WHERE is_delete=0")
    List<RoomDevice> findAllRoomDev();

    //    查询房间地址表
    @Select("SELECT * FROM `room_address` WHERE is_delete=0")
    List<RoomAddress> findAllRoomAddr();

    //    查询房间图片表
    @Select("SELECT * FROM `room_images` WHERE is_delete=0")
    List<RoomImages> findAllRoomImages();

    //    根据id查询
    @Select("SELECT * FROM room WHERE room_id=#{roomId} AND is_delete=0")
    Room findRoomById(String roomId);

    //    根据id查询
    @Select("SELECT * FROM room_address WHERE room_id=#{roomId} AND is_delete=0")
    RoomAddress findRoomAddrById(String roomId);

    //    根据id查询
    @Select("SELECT * FROM room_device WHERE room_id=#{roomId} AND is_delete=0")
    List<RoomDevice> findRoomDevById(String roomId);

    //    根据id查询
    @Select("SELECT * FROM room_images WHERE room_id=#{roomId} AND is_delete=0")
    RoomImages findRoomImagesById(String roomId);

    //    添加room
    @Insert("INSERT INTO `room` VALUES(#{roomId},#{star},#{roomStatus},#{isDelete})")
    int addRoom(RoomDto roomDto);

    @Insert("INSERT INTO `room_address` VALUES(#{roomId},#{province},#{city},#{district},#{detail},#{longitude},#{latitude},#{isDelete})")
    int addRoomAddr(RoomAddress roomAddress);

    @Insert("INSERT INTO `room_device` VALUES(#{roomDevId},#{roomId},#{devId},#{isDelete})")
    int addRoomDevice(RoomDevice roomDevice);

    @Insert("INSERT INTO `room_images` VALUES(#{roomUrlId},#{roomUrl},#{roomId},#{isDelete})")
    int addRoomImages(RoomImages roomImages);


    //    删除room
    @Update("UPDATE `room` SET is_delete = 1 WHERE room_id = #{roomId} AND is_delete=0")
    int delRoom(String roomId);

    @Update("UPDATE `room_address` SET is_delete = 1 WHERE room_id = #{roomId} AND is_delete=0")
    int delRoomAddr(String roomId);

    @Update("UPDATE `room_device` SET is_delete = 1 WHERE room_id = #{roomId} AND is_delete=0")
    int delRoomDevice(String roomId);

    @Update("UPDATE `room_images` SET is_delete = 1 WHERE room_id = #{roomId} AND is_delete=0")
    int delRoomImages(String roomId);

    @Update("UPDATE `room` SET star=#{star},room_status=#{roomStatus},is_delete=#{isDelete} WHERE room_id=#{roomId} AND is_delete=0")
    int updateRoom(RoomDto roomDto);

    @Update("UPDATE `room_address` SET province=#{province},city=#{city},district=#{district},detail=#{detail},longitude=#{longitude},latitude=#{latitude},is_delete=#{isDelete} WHERE room_id=#{roomId} AND is_delete=0")
    int updateRoomAddr(RoomAddress roomAddress);

    @Update("UPDATE `room_device` SET room_id=#{roomId},dev_id=#{devId},is_delete=#{isDelete} WHERE room_dev_id=#{roomDevId} AND is_delete=0")
    int updateRoomDevice(RoomDevice roomDevice);

    @Update("UPDATE `room_images` SET room_url=#{roomUrl},room_id=#{roomId},is_delete=#{isDelete} WHERE room_url_id=#{roomUrlId} AND is_delete=0")
    int updateRoomImages(RoomImages roomImages);

    @Insert("insert into  `room_device` (`room_id`,`dev_id`) values(#{roomId},#{devId})")
    boolean addRoomDev(String roomId, String devId);


}
